﻿namespace homewizard
{
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class hwLogin : Page
    {
        protected Button Button1;
        protected HtmlForm form1;
        protected Label Label1;
        protected Label lbllable;
        protected TextBox txtName;
        protected TextBox txtPassword;

        protected void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                if ((this.txtName.Text != "") && (this.txtPassword.Text != ""))
                {
                    DataSet dataSet = new DataSet();
                    SqlConnection selectConnection = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
                    SqlCommand command = new SqlCommand();
                    string selectCommandText = "select *From wsLogin where vUserName='" + this.txtName.Text + "' and vPassword='" + this.txtPassword.Text + "'";
                    selectConnection.Open();
                    new SqlDataAdapter(selectCommandText, selectConnection).Fill(dataSet);
                    if ((dataSet.Tables.Count > 0) && (dataSet.Tables[0].Rows.Count > 0))
                    {
                        this.Session["isLoggedIn"] = dataSet.Tables[0].Rows[0]["vUserName"].ToString();
                        if ((base.Request.QueryString["ReturnUrl"].ToString() != "") && (base.Request.QueryString["ReturnUrl"].ToString() != null))
                        {
                            string str2 = base.Request.QueryString["ReturnUrl"].ToString();
                            base.Response.Redirect("~/" + str2);
                        }
                        else
                        {
                            base.Response.Redirect("~/showdata.aspx");
                        }
                    }
                    else
                    {
                        base.Response.Write("No Authorized...!!!");
                    }
                    selectConnection.Close();
                }
                else
                {
                    base.Response.Write("Please Enter UserName and Password !!");
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
        }
    }
}

